package com.loveprogrammer.eternity.model.effect;

import com.loveprogrammer.eternity.enums.EffectTimeEnum;
import com.loveprogrammer.eternity.model.Character;
import com.loveprogrammer.eternity.model.attack.AttackResult;

import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * @version 1.0.0
 * @description:
 * @author: eric
 * @date: 2023-02-15 17:37
 **/
public class SuckBloodEffect extends AbstractEffect{
    private int percent;

    public SuckBloodEffect(String id,int percent) {
        super(id);
        this.percent = percent;
    }

    @Override
    public boolean trigger(EffectTimeEnum effectTimeEnum) {
        return effectTimeEnum.equals(EffectTimeEnum.ATTACK_AFTER);
    }

    @Override
    public StringBuilder doUpdate(Character attack, AttackResult entity,
                            List<? extends Character> attackList, Character[] defence) {
        StringBuilder builder = new StringBuilder();
        if(defence == null){
            return builder;
        }
        // 吸血 普通攻击造成吸血
        int hp = entity.getHarm() * defence.length * percent / 100;
        builder.append("-[附加吸血").append(hp).append("点]");
        if (attack.hp().addAndGet(hp) > attack.getHpMax()) {
            attack.setHp(new AtomicInteger(attack.getHpMax()));
        }
        return builder;
    }

    public int getPercent() {
        return percent;
    }

    public void setPercent(int percent) {
        this.percent = percent;
    }
}
